# _*_ coding: utf-8 _*_
"""
    Created by Yiutto on 2024/11/22.
"""
from flask import Flask, request, jsonify, render_template, redirect, url_for
import json
from generate_code import queryData

app = Flask(__name__)

@app.route('/fill')
def fill():
    return render_template('fill.html')

@app.route('/success/<name>')
def success(name, result):
    return result

@app.route("/getdataxcode", methods=["GET", "POST"])
def getdataxcode():
    host = request.args.get("host")
    port = request.args.get("port")
    user = request.args.get("user")
    pwd = request.args.get("pwd")
    db = request.args.get("db")
    tb = request.args.get("tb")
    et = request.args.get("et")
    pt = request.args.get("pt")
    wh = request.args.get("wh")
    plt = request.args.get("plt")
    st = request.args.get("st")
    hdb = request.args.get("hdb")
    #result = {}
    result = "Warning: You must select \"etl_type\" and \"is_partition\", or you get no code;"
    # 二者不为空就调用
    if (isinstance(et,str) and isinstance(pt,str)):
        createTableStr, dataxJsonStr, shellSrciptStr = queryData(host, int(port), user, pwd, db, tb, int(et), int(pt), int(wh), int(plt), st, hdb)
        #result["create_table"] = createTableStr
        #result["datax_json"] =  dataxJsonStr
        #result["shell_script"] =  shellSrciptStr
        result = createTableStr.replace('\n','<br>').replace(' ','&nbsp;') + '<br><br>' +  dataxJsonStr.replace('\n','<br>').replace(' ','&nbsp;') + '<br><br>' + shellSrciptStr.replace('\n','<br>').replace(' ','&nbsp;')
    #return json.dumps(result)
    return result
    #return redirect(url_for('success',name = '11', result = result))
if __name__ == "__main__":
    app.run(host="nn1", port=9504)